package com.codename1.samples;


import static com.codename1.ui.CN.*;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Dialog;
import com.codename1.ui.Label;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.Resources;
import com.codename1.io.Log;
import com.codename1.ui.Toolbar;
import java.io.IOException;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.io.NetworkEvent;
import com.codename1.ui.BrowserComponent;
import com.codename1.ui.Button;
import com.codename1.ui.layouts.BorderLayout;

/**
 * This file was generated by <a href="https://www.codenameone.com/">Codename One</a> for the purpose 
 * of building native mobile applications using Java.
 */
public class FullScreenWithBrowserComponentSample {

    private Form current;
    private Resources theme;
    
    private BrowserForm browserForm;
    
    class BrowserForm extends Form {
        BrowserComponent bc = new BrowserComponent();
        BrowserForm() {
            super(new BorderLayout());
            add(BorderLayout.CENTER, bc);
            Button b = new Button("Toggle Fullscreen");
            b.addActionListener(e->{
                if (Display.getInstance().isInFullScreenMode()) {
                    Display.getInstance().exitFullScreen();
                } else {
                    Display.getInstance().requestFullScreen();
                }
            });
            add(BorderLayout.SOUTH, b);
        }
        
        void setPage(String content) {
            bc.setPage(content, null);
        }
    }

    public void init(Object context) {
         // use two network threads instead of one
        updateNetworkThreadCount(2);
        requestFullScreen();

        theme = UIManager.initFirstTheme("/theme");

        // Enable Toolbar on all Forms by default
        Toolbar.setGlobalToolbar(true);

        // Pro only feature
        Log.bindCrashProtection(true);
    }
    
    public void start() {
         if (current != null)
        {
            current.show();
        }
        else
        {
            browserForm = new BrowserForm();

            current = browserForm;
            browserForm.show();

            browserForm.setPage("<html><body>HELLO WORLD</body><html>");
            test();
        }
    }

    public void stop() {
        current = getCurrentForm();
        if(current instanceof Dialog) {
            ((Dialog)current).dispose();
            current = getCurrentForm();
        }
    }
    
    public void destroy() {
    }
    public void test()
    {
        browserForm.setPage("<html><body>HELLO WORLD</body><html>");
    }
}
